package com.surprise.bweb.utils;

import java.util.Map;

import com.surprise.base.util.JacksonUtils;
import com.surprise.bweb.bo.CommonRes;
import com.surprise.bweb.bo.CommonRes.ErrorMsg;
import com.surprise.webcommon.AppStatusCode;

/**
 * ResponseUtils.java
 * @author nick
 * @since 2015年8月18日
 */
public class ResponseUtils {
	public static CommonRes exception(Exception e) {
		return new CommonRes().setStatus(1).setMsg(
				new ErrorMsg().setGlobal(e.getMessage()));
	}
	
	public static CommonRes errorMsg(String msg) {
		return new CommonRes().setStatus(AppStatusCode.EXCEPTION_OCCUR).setMsg(
				new ErrorMsg().setGlobal(msg));
	}
	
	public static CommonRes errorMsg(int code, String msg) {
		return new CommonRes(code, new ErrorMsg().setGlobal(msg));
	}
	
	public static CommonRes errorMsg(Map<String, String> errorMsgs) {
	    String errorMsg = JacksonUtils.toJson(errorMsgs);
	    
		return new CommonRes(AppStatusCode.PARAMETER_ERROR,
				new CommonRes.ErrorMsg().setGlobal(errorMsg));
	}
}
